package cn.tedu.cs.baking.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@Slf4j
public class WebMvcConfiguration implements WebMvcConfigurer {
    @Value("${file.save-path}")
    private String dirPath;

//    @Override
//    public void addCorsMappings(CorsRegistry registry) {
//        registry.addMapping("/**")
//                .allowedHeaders("*")
//                .allowedMethods("*")
//                .allowedOriginPatterns("*")
//                .allowCredentials(true)
//                .maxAge(3600);
//    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        String sysPath = System.getProperty("user.dir");
        String path = sysPath.replaceAll("\\\\", "/");
        String filePath = "file:"+path+dirPath.substring(1);
        log.info("静态路径:{}",filePath);
        registry.addResourceHandler("/pic/**").addResourceLocations(filePath);
    }
}
